<?php

namespace app\common\dao\system\upload;

use think\db\BaseQuery;
use app\common\dao\BaseDao;
use app\traits\CategoryDao;
use app\common\model\system\upload\SystemUploadGroupModel;

class SystemUploadGroupDao extends BaseDao
{
    use CategoryDao;

    /**
     * @return SystemUploadGroupModel
     */
    protected function getModel(): string
    {
        return SystemUploadGroupModel::class;
    }

    /**
     * @param int|null $propertyId 企业ID
     * @return BaseQuery
     */
    public function search(int $propertyId, array $where = [])
    {
        return $this->getModel()::getDB()
            ->when($propertyId !== null, function ($query) use ($propertyId) {
                $query->where('property_id', $propertyId);
            })
            ->when(isset($where['user_id']) && $where['user_id'] !== '', function ($query) use ($where) {
                $query->where('user_id', $where['user_id']);
            });
    }

}
